Skip to content

Refactor auth env to use CLI's resolved auth context#4904

Open
simonfaltum wants to merge 1 commit intomainfrom
simonfaltum/auth-env-refactor
Open

Refactor auth env to use CLI's resolved auth context#4904
simonfaltum wants to merge 1 commit intomainfrom
simonfaltum/auth-env-refactor

Conversation

@simonfaltum
Copy link
Copy Markdown
Member

Why

auth env had its own custom auth resolution logic (local --host/--profile flags, manual profile-to-host matching via ini file scanning). It didn't go through the standard CLI auth chain, so it couldn't resolve auth from bundle context, default profiles, or environment variables. It was effectively a standalone tool that only worked with explicit profile or host arguments.

The command should return the environment variables needed to authenticate as the exact same identity the CLI is currently authenticated as.

Changes

Refactored to use the CLI's standard auth resolution (root.MustAnyClient + cmdctx.ConfigUsed), same pattern as auth describe. Uses auth.Env(cfg) from libs/auth/env.go to generate env vars. This means it now works with bundle context, env var auth, default profiles, and all other standard auth paths.

Before: databricks auth env --host https://my-workspace.cloud.databricks.com with custom profile matching.
Now: databricks auth env returns the env vars for whatever identity the CLI resolved through its normal auth chain.

Also adds --output text support for KEY=VALUE lines with proper shell quoting.

Breaking changes:

  • Removed command-specific --host and --profile flags (the inherited flags from the parent auth and root commands cover this)
  • JSON output is a flat map instead of {"env": {...}}
  • Only the primary env var per attribute is emitted (via auth.Env, consistent with bundle run)

Removed ~120 lines of dead code: canonicalHost, resolveSection, loadFromDatabricksCfg, collectEnvVars, ErrNoMatchingProfiles.

Test plan

  • Unit tests for text and JSON output modes
  • Unit test for backward compatibility (no explicit --output keeps JSON)
  • Unit test for value quoting in text mode (spaces, special chars, single quotes, newlines)
  • Existing cmd/auth tests pass

Use root.MustAnyClient and auth.Env instead of custom profile/host
resolution logic. auth env now returns the environment variables for the
exact identity the CLI is authenticated as, including bundle context and
all standard auth resolution paths.

Also adds --output text support for KEY=VALUE lines with proper shell
quoting.

Breaking changes:
- Removed command-specific --host and --profile flags (use inherited flags)
- JSON output is a flat map instead of wrapped in {"env": ...}
- Only the primary env var per attribute is emitted (via auth.Env)

Co-authored-by: Isaac
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

Eligible reviewers

Could not determine reviewers from git history. Based on CODEOWNERS, these people or teams could review:

@andrewnester, @anton-107, @denik, @pietern, @shreyas-goenka

Suggestions based on git history of 2 changed files (0 scored). See CODEOWNERS for path-specific ownership rules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant